package com.heima.homeservicemanagementsystem.service.impl;

import com.heima.homeservicemanagementsystem.service.VerifyService;
import com.heima.homeservicemanagementsystem.utils.CodeUtils;
import com.heima.homeservicemanagementsystem.utils.RedisClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.PropertySource;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description
 * @Author jcf
 * @Date 2025/3/11
 */
@Slf4j
@Service
@PropertySource("classpath:application.yaml")

public class VerifyServiceImpl implements VerifyService {
    @Autowired
    private RedisClient redisClient;
    @Autowired
    private EmailService emailService;


    @Override
    public String getCode(String phone) {

        if (phone != null) {
            String code = CodeUtils.generateCode();
            log.info("验证码为：{}", "mobileCode-" + phone);
            redisClient.set("mobileCode-" + phone, code, 1000L * 60);
            return code;
        }

//        System.out.println(code);
        return "0";
    }

    @Override
    public String getemail(String email) {

        String code = CodeUtils.generateCode();
        log.info("验证码为：{}", "emailCode-" + email);
        emailService.sendHtmlMail(email, "【邮箱验证码】欢迎使用逃逃家政管理系统", "<p>您的邮箱验证码是:<p><p style=\" font-weight: bold;text-align: center;color: red;\">" + code + "</p>");
        redisClient.set("emailCode-" + email, code, 1000L * 60 * 5);
        return "发送成功";
    }


}
